package com.xigua.JucOfBeautiful.chapterOne.sleep1_5;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author LiRongHua
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: ${todo}
 * @date 2022/1/2222:41
 */
public class SleepTest {

    private static final Lock lock = new ReentrantLock();

    public static void main(String[] args) throws InterruptedException {
        Thread threadOne = new Thread(()->{
            lock.lock();
            System.out.println("threadOne is in sleep");
            try {
                Thread.sleep(10000);
                System.out.println("threadOne is in awaked");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.unlock();
        });

        Thread threadTow = new Thread(()->{
            lock.lock();
            System.out.println("threadTow is in sleep");
            try {
                Thread.sleep(10000);
                System.out.println("threadTow is in awaked");
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            lock.unlock();
        });

        threadOne.start();
        threadTow.start();
        Thread.sleep(2000);
        threadOne.interrupt();

    }
}
